package horsechess.client.data;

import horsechess.client.gui.GUIClient;
import horsechess.client.handle.ChessMan;
import horsechess.util.Point;
import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JLabel;

/**
 * @author Administrator
 * @version 2.2
 * @created 17-Apr-2011 11:50:32 AM
 */
public class PlayerData {

    private String username;
    private int colorChessMan;
    private int numberOfChessMan;
    private int finalChessMan;
    public List<ChessMan> listOfChessMan = new ArrayList<ChessMan>();
    public List<Point> listOfFinalPosition = new ArrayList<Point>(6);
    private int score;
    public ArrayList<JLabel> horseInFinals=new ArrayList<JLabel>(6);


   

    /**
     * Init numberOfChess with numberOfChessMan
     * Init finalChessMan with Zero
     * for each chess man on board
     * 	Initialize temp type ChessMan
     * 	Add temp into listOfChessMan
     *
     * @param numberOfChessMan
     */
    public PlayerData(int numberOfChessMan) {
        setNumberOfChessMan(numberOfChessMan);
        finalChessMan = 0;
        for (int i = 0; i < numberOfChessMan; i++) {
            ChessMan temp = new ChessMan();
            listOfChessMan.add(temp);
        }
        initHorseInFinals();
    }

    private void initHorseInFinals(){
        horseInFinals.add(null);
        horseInFinals.add(null);
        horseInFinals.add(null);
        horseInFinals.add(null);
        horseInFinals.add(null);
        horseInFinals.add(null);
    }

    public boolean isHorseJoin(int posOfFinal){
        if (horseInFinals.get(posOfFinal)!=null) {
            return false;
        }
        return true;
    }

    public boolean isHasHorse(Point p) {
        Component[] components = GUIClient.uIClient.pnlChessBoard.getComponents();
        for (int i = 0; i < components.length; i++) {
            Component component = components[i];
            if (component instanceof JLabel) {
                JLabel picHorse = (JLabel) component;
                int x = (int) picHorse.getBounds().getX();
                int y = (int) picHorse.getBounds().getX();
                //System.out.println(new  Point(x,y).toString());
                if (p.getX() == x || p.getY() == y) {
                    return true;
                }
            }
        }
        return false;
    }

   

//    /**
//     * Kick the chessman got 5 point
//     * @param posOnBoard
//     */
//    public void kickChessMan(ChessBoardData cb) {
//       PlayerData player = (PlayerData) cb.players.get(chessMan - 1);
//
//        for (int i = 0; i < player.getNumberOfChessMan(); i++) {
//            ChessMan cm = (ChessMan) player.listOfChessMan.get(i);
//            if (cm.getChessman().getPositionOnBoard() == posOnBoard) {
//                System.out.println("Chessman of:"+player.getUsername()+ " have been kicked. CM No."+i);
//                Point p = cm.getChessman().getPositionInCage();
//                cm.getGUIChessMan().picChessMan.setBounds(p.getX(), p.getY(), 33, 33);
//                cm.getChessman().setPositionOnBoard(-1);
//                return;
//            }
//        }
//        //player.setScore(player.getScore() + 5);
//    }

    
    /**
     * Getter && Setter
     */
    public int getColorChessMan() {
        return colorChessMan;
    }

    public void setColorChessMan(int colorChessMan) {
        this.colorChessMan = colorChessMan;
    }

    public int getNumberOfChessMan() {
        return numberOfChessMan;
    }

    public void setNumberOfChessMan(int numberOfChessMan) {
        this.numberOfChessMan = numberOfChessMan;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

   

    public int getFinalChessMan() {
        return finalChessMan;
    }

    public void setFinalChessMan(int finalChessMan) {
        this.finalChessMan = finalChessMan;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

  
}
